<?php

/*
 * This class is used for as Model for Product table 
 */

class Model_Propertytag extends Model_Base {

    protected $_name = 'property_tag';
    protected $_primaryKey = 'prpt_id';

    public function fetchTagByPropertyId($id) {

        $finlaArray = Array();
        $finlaArray['SECONDRY'] = '';
        $finlaArray['INDOOR'] = '';
        $finlaArray['OUTDOOR'] = '';
        $finlaArray['TENANCY'] = '';


        $select = $this->select()
                ->from(array('que' => 'property_tag'))
                ->where('prp_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            $petsArray = Array();
            $garageArray = Array();
            $parkingArray = Array();
            $warehouseArray = Array();
            $resultData = $data->toArray();
            foreach ($resultData as $_value) {
                if ($_value['prp_type'] == 'SECONDRY') {
                    $petsArray[] = $_value['prp_tag'];
                }

                if ($_value['prp_type'] == 'INDOOR') {
                    $garageArray[] = $_value['prp_tag'];
                }

                if ($_value['prp_type'] == 'OUTDOOR') {
                    $parkingArray[] = $_value['prp_tag'];
                }

                if ($_value['prp_type'] == 'TENANCY') {
                    $warehouseArray[] = $_value['prp_tag'];
                }
            }

            if (count($petsArray) > 0) {
                $finlaArray['SECONDRY'] = $petsArray;
            }

            if (count($garageArray) > 0) {
                $finlaArray['INDOOR'] = $garageArray;
            }

            if (count($parkingArray) > 0) {
                $finlaArray['OUTDOOR'] = $parkingArray;
            }

            if (count($warehouseArray) > 0) {
                $finlaArray['TENANCY'] = $warehouseArray;
            }

            return $finlaArray;
        } else {
            return $finlaArray;
        }
    }

}
